<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>

<html>
<head>

<!-- <script type="text/javascript" src="js/CheckCardIDUtil.js"> -->
<script type="text/javascript">
var listUrl="rest/userList.do";
var sexJson; 
var userStatusJson;
var city;


$(document).ready(function () {         
	sexJson=syncGetDictListByTypeName('sex');
	
	//orgTreeJson=syncGetOrgTree();
	city = syncGetDictListByTypeName('city');
	
	 $(":radio").click(function() { 
	  if($(this).val() == 5){
	         $("#phoneDiv").show();
	  }else{
	         $("#phoneDiv").hide();
	  }
	   
	}); 


})//end ready


function addCoupon() {
	   $('#user-fm').form('submit', {
        url: 'rest/couponAdd.do',        
        onSubmit: function () {
        	if(!$("input[name='type']").val()){
        	  $.messager.alert('操作提示', "优惠券类型不能为空", 'error');	
        	  return false; 
        	}
        	if(!$("#produceMoney").val() || isNaN($("#produceMoney").val())){
        	  $.messager.alert('操作提示', "优惠券金额不能为空或者字符串，只能为数字", 'error');	
        	  return false; 
        	}
        	if(!$("#produceAmount").val() || isNaN($("#produceAmount").val())){
        	  $.messager.alert('操作提示', "优惠券数量不能为空或者字符串，只能为数字", 'error');	
        	  return false; 
        	}
        	var couponType = $("#overdueTime").datebox("getValue");
        	if(!couponType){
        	  $.messager.alert('操作提示', "优惠券截至日期不能为空", 'error');	
        	  return false; 
        	}
        },
        success: function (result) {   
            var aas = jQuery.parseJSON(result);
        	if (aas.retCode == "0000") {
        	    $.messager.defaults = {
					ok : "确定",
				};
				$.messager.alert('操作提示', "添加成功",'info', function() {
					    var url2 = "coupon/index.do";
						$.post(url2, {}, function(data) {
							$("#center").empty();
							$("#center").html(data);
							$.parser.parse($("#center"));
						});
				});	
									
			} else {
			   if(aas.retMsg){
			      $.messager.alert('操作提示', aas.retMsg, 'error');
			   }else{
			      $.messager.alert('操作提示', "添加失败", 'error');
			   }
			}
        }
    });
}

function back(url){
	$.get(url, {}, function(data){
		$("#center").empty();
        $("#center").html(data);
        $.parser.parse($("#center"));
    });
}

</script>
</head>
<body>
		
<div class="linkbar"><a>运营管理</a>/<a>优惠券管理</a>/<a>添加优惠券</a></div>

		<div id="user-add">
			<form id="user-fm" method="post" novalidate>
			<div class="fitem">
				<label>优惠券类型:</label> 
				<input id="type" name="type" type="radio"  class="easyui-validatebox" style="width:16px;" value="1" checked><label>申请账号时发放</label></input>
                <input id="type" name="type" type="radio"  class="easyui-validatebox" style="width:16px;" value="2"><label>支付完成时发放</label></input>
                <input id="type" name="type" type="radio" class="easyui-validatebox" style="width:16px;" value="3"><label>退款时发放</label></input>
                <input id="type" name="type" type="radio"  class="easyui-validatebox" style="width:16px;" value="4"><label>向推荐人发放</label></input>
                <input id="type" name="type" type="radio"  class="easyui-validatebox" style="width:16px;" value="5"><label>向指定用户发放</label></input>
			</div>

			<div class="fitem" id="phoneDiv" style="display:none;">
				<label>输入指定用户的id或手机号:</label> 
				<input name="phone" class="easyui-validatebox"/>
			</div>

			<div class="fitem">
				<label>优惠券名称:</label> 
				<input name="produceName" id = "produceName" class="easyui-validatebox" missingMessage="该输入项不能为空！" data-options="required:true" />
			</div>

			<div class="fitem">
				<label>优惠券金额:</label> 
				<input name="produceMoney" id = "produceMoney"
					class="easyui-validatebox" missingMessage="该输入项不能为空！"
					data-options="required:true" />
			</div>
			<div class="fitem">
				<label>优惠券发放数量:</label> 
				<input name="produceAmount" id = "produceAmount"
					class="easyui-validatebox" missingMessage="该输入项不能为空！"
					data-options="required:true"/>
			</div>
			<div class="fitem">
				<label>优惠券截至时间:</label> 
				<input name="overdueTime" id = "overdueTime"
					class="easyui-datebox" missingMessage="该输入项不能为空！"
					data-options="required:true"/>
			</div>
			<div class="fitem">
				<label>优惠券说明:</label> 
				<input class="easyui-textbox" name="couponMessge" id = "couponMessge" 
	             data-options="multiline:true" style="height:100px;width:200px">
	            </input>
			</div>				
			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok" 	onclick="addCoupon()">保存</a> 
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="back('coupon/addCoupon.do')">返回</a>
		</div>
		

</body>
</html>